/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.setting.view;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.widget.TextView;

import com.suozhang.framework.component.http.RxDataProcessFactory;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.zoomimageview.ZoomImageView;
import com.yiqi.liebang.entity.enums.CertificateImage;
import com.yiqi.liebang.framework.api.HomeApi;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class ImageActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.iv_rZ)
    ZoomImageView ivRZ;


    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_image;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        super.initView();


    }

    @Override
    protected void initData() {
        Integer type = this.getIntent().getIntExtra("type", 0);
        String userId=this.getIntent().getStringExtra("userid");
        if (type != null&&!TextUtils.isEmpty(userId)) {
            initToolBar(mToolbar,CertificateImage.getName(type),true,true);
            getImage(type,userId);
        }


    }

    private void getImage(Integer type, String id) {
        AM.api().createApiService(HomeApi.class)
                .getUserMosaic(type,id)
                .compose(RxDataProcessFactory.dataPrepAndIoToMainTransformer())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        showLoading(d);
                    }

                    @Override
                    public void onNext(String s) {
                        dismissLoading();
                        if (!TextUtils.isEmpty(s)) {
                            AM.image().bind(s, ivRZ);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        dismissLoading();
                    }

                    @Override
                    public void onComplete() {
                        dismissLoading();
                    }
                });

    }
}